import 'package:flutter/material.dart';

class RetryButtonStyle {
  final Decoration buttonDecoration;
  final TextStyle tipTextStyle;
  final EdgeInsetsGeometry buttonPadding;
  final Size buttonSize;
  final TextStyle buttonTextStyle;

  RetryButtonStyle({
    this.buttonDecoration = const BoxDecoration(
      color: Colors.blue,
      borderRadius: BorderRadius.all(Radius.circular(3.0)),
    ),
    this.tipTextStyle = const TextStyle(color: Colors.white, fontSize: 14.0),
    this.buttonPadding = const EdgeInsets.only(top: 10.0),
    this.buttonSize = const Size(84.0, 36.0),
    this.buttonTextStyle = const TextStyle(
      color: Colors.white,
      fontSize: 14.0,
    ),
  });
}

class VideoRetryButton extends StatelessWidget {
  final bool hasError;
  final String errorMsg;
  final VoidCallback? onRetry;
  final RetryButtonStyle retryButtonStyle;

  VideoRetryButton({
    Key? key,
    this.hasError = false,
    this.errorMsg = '',
    this.onRetry,
    RetryButtonStyle? retryButtonStyle,
  })  : retryButtonStyle = retryButtonStyle ?? RetryButtonStyle(),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    if (hasError) {
      return DecoratedBox(
        decoration: BoxDecoration(
          color: Colors.black.withOpacity(0.5),
        ),
        child: Align(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                errorMsg,
                style: retryButtonStyle.tipTextStyle,
              ),
              GestureDetector(
                onTap: onRetry,
                child: Padding(
                  padding: retryButtonStyle.buttonPadding,
                  child: Container(
                    width: 100.0,
                    height: 40.0,
                    alignment: Alignment.center,
                    decoration: retryButtonStyle.buttonDecoration,
                    child: Text(
                      '重试',
                      style: retryButtonStyle.buttonTextStyle,
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      );
    } else {
      return const SizedBox();
    }
  }
}
